function [p,ai] = proddl(sd,md,lcd,rv,cpn,yld,per,basis)
%PRODDL Price with odd last period.
%   Returns the price P and accrued interest AI of a security with odd last
%   period.
%
%   [P,AI] = PRODDL(SD,MD,LCD,RV,CPN,YLD)
%   [P,AI] = PRODDL(SD,MD,LCD,RV,CPN,YLD,PER)
%   [P,AI] = PRODDL(SD,MD,LCD,RV,CPN,YLD,PER,BASIS)
%
%   Enter dates as serial date numbers or date strings.
%
%   Inputs:
%       SD      -  Settlement date
%       MD      -  Maturity date
%       LCD     -  Last coupon date
%       RV      -  Par value
%       CPN     -  Coupon rate
%       YLD     -  Annual yield
%
%   Optional Inputs:
%       PER     - the number of coupon periods per year
%                  1 - annual
%                  2 - semi-annual (default)
%                  3 - three times per year
%                  4 - quarterly
%                  6 - bi-monthly
%                 12 - monthly
%
%       BASIS   -  the day-count basis:
%                  0 = actual/actual (default)
%                  1 = 30/360 SIA
%                  2 = actual/360
%                  3 = actual/365
%                  4 = 30/360 PSA
%                  5 = 30/360 ISDA
%                  6 = 30E/360
%                  7 = actual/365 Japanese
%                  8 - actual/actual ISMA
%                  9 - actual/360 ISMA
%                 10 - actual/365 ISMA
%                 11 - 30/360 ISMA
%                 12 - actual/365 ISDA
%
%   Using the following data,
%
%       SD = '02/07/1993'
%       MD = '08/01/1993'
%       LCD = '02/04/1993'
%       RV = 100
%       CPN = 0.0650
%       YLD = 0.0535
%       PER = 2
%       BASIS = 1
%
%   [p,ai] = proddl(sd,md,lcd,rv,cpn,yld,per,basis)
%
%   returns p = 100.54 and ai = 0.05.
%
%   See also PRODDF, PRODDFL, PRBOND, YLDODDL.
%
%   Reference: Mayle, Standard Securities Calculation Methods, Volumes
%              I-II, 3rd edition.  Formulas 11, 13, 14, 15.

% Copyright 1995-2006 The MathWorks, Inc.
% $Revision: 1.7.2.8 $   $Date: 2007/11/07 18:29:59 $

if nargin < 8
    basis = 0;
end

if nargin < 7
    per = 2;
end

if nargin < 6
    error('finance:proddl:notEnoughInputs',...
        'Missing one of SD, MD, LCD, RV, CPN, and YLD.')
end

if any(any(ischar(sd) || ischar(md) || ischar(lcd)))
    sd = datenum(sd);
    md = datenum(md);
    lcd = datenum(lcd);
end

if length(sd) == 1
    sd = sd*ones(size(md));
end

if length(md) == 1
    md = md*ones(size(sd));
end

if length(lcd) == 1
    lcd = lcd*ones(size(sd));
end

if length(rv) == 1
    rv = rv*ones(size(sd));
end

if length(yld) == 1
    yld = yld*ones(size(sd));
end

if length(cpn) == 1
    cpn = cpn*ones(size(sd));
end

if length(per) == 1
    per = per*ones(size(sd));
end

if length(basis) == 1
    basis = basis*ones(size(sd));
end

if any(~isvalidbasis(basis))
    error('finance:proddl:invalidBasis',...
        'Invalid day count basis specified.');
end

if checksiz([size(sd);size(md);size(lcd);size(rv);size(yld);size(cpn);...
        size(per);size(basis)],mfilename)
    return
end

p = zeros(size(sd));
for i = 1:length(sd(:));
    if checkrng(str2mat('lcd','cpn','yld','per','sd'),...
            [lcd(i),cpn(i),yld(i),per(i),sd(i)],[-inf 0 0 0 -inf],...
            [md(i) inf inf inf md(i)],str2mat('-inf','0','0','0','-inf'),...
            str2mat('md','inf','inf','inf','md'),['l';'e';'e';'l';'l'],...
            ['e';'l';'l';'l';'e'],mfilename)
        return
    end
    if checktyp('per',per(i),'int',mfilename)
        return;
    end
end  % End for loop

[p,ai] = bndprice(yld,cpn,sd,md,per,basis,[],[],[],lcd,[],rv);

% [EOF]
